package com.netsdk.socket;

import cn.hutool.core.io.FastByteArrayOutputStream;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;

import java.io.*;
import java.net.Socket;

public class SocketTest {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("10.238.87.37",8091);
        while (true){
            InputStream inputStream = socket.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            byte[] buffer = new byte[1024];
            StringBuilder sb = new StringBuilder();
            while (true){
                String str = reader.readLine();
                System.out.println(str);
//                int length = inputStream.read(buffer);
//                if(length == -1){
//                    break;
//                }
//                sb.append(new String(buffer,0,length));
            }
//            reader.read()
//            FastByteArrayOutputStream fastByteArrayOutputStream = new FastByteArrayOutputStream();
//            OutputStreamWriter writer = new OutputStreamWriter(fastByteArrayOutputStream);
//            IoUtil.copy(reader,writer);
//            byte[] bytes = IoUtil.readBytes(inputStream, false);
//            String str = StrUtil.str(fastByteArrayOutputStream.toByteArray(), CharsetUtil.UTF_8);
//            System.out.println(sb.toString());
        }
    }
}
